<template>
  <div>
    <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="活动名称">
        <el-input v-model="form.name"></el-input>
      </el-form-item>
      <el-form-item label="年龄">
        <el-input v-model="form.age"></el-input>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="add()">立即创建</el-button>
        <el-button>取消</el-button>
      </el-form-item>
    </el-form>

    <el-table :data="tableData" style="width: 100%">
      <el-table-column prop="name" label="姓名" > </el-table-column> 
      <el-table-column prop="age" label="年龄" > </el-table-column> 
      <el-table-column prop="time" label="日期" > </el-table-column>
      
      <el-table-column label="操作">
      <template slot-scope="scope"> 
        <el-button
          size="mini"
          type="danger"
          @click="del(scope.$index, scope.row)">删除</el-button>
      </template>
    </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { mapMutations, mapState } from 'vuex';

export default {
  data() { 
    return {
      tableDate:[],
      form: {
        name: "",
        age: "",
        time: new Date().toLocaleDateString(),
      },
    };
  },
  computed:{
    ...mapState(['tableData'])
  },
  mounted() {

  },

  methods: {
    ...mapMutations(['addobj','delobj']),
    add(){
      //非空
      if(this.form.name==""||this.form.age==""){
        alert('数据不能为空')
      }
      //加数据
      var obj={name:this.form.name, age:this.form.age,time:this.form.time}
      //调用数据
      this.addobj(obj)
      //提示
      this.$message.success('添加了哦');
      //清空
      this.form.name=this.form.age=""
    },
    del(index,row){
      this.delobj(index)
    }
  },
};
</script>

<style scoped></style>
